<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : xmlProject.xsl
    Created on : Utorok, 2013, máj 7, 7:35
    Author     : Martin Horváth
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns="http://www.w3.org/1999/xhtml">
   
    <xsl:output method="xml"
                doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
                doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
                encoding="UTF-8"
                indent="yes"
    />

    <!-- TODO customize transformation rules
         syntax recommendation http://www.w3.org/TR/xslt
    -->
   
   

   
    <xsl:template match="/">
        <xsl:variable name="root" select="1.4142135623731"/>
        <html>
            <head>
                <style type="text/css">
                    body
                    {
                    background: url('pozadie.gif');
                    }
                    h1
                    {
                    color:#81c055;
                    text-align:center;
                    font-family:Calibri;
                    font-size:30pt;
                    text-transform: uppercase;
                    }
                    h2 {
                    color:#c7d93d;
                    text-align:center;
                    font-family:Calibri;
                    font-size:10pt;
                    text-transform: uppercase;
                    margin-top:-35px;
                    }
                    h3 { color:#94d4c8;
                    text-align:center;
                    font-family:Calibri;
                    font-size:70pt;
                    opacity:0.6;
                    }
                </style>
                <title>Friends</title>
                <meta http-equiv="Content-Style-Type" content="text/css" />
            </head>
            <body>
                <h1>Towns where your friends live</h1>
                <h2>Moderní značkovací jazyky</h2>

                <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="95%" height="400">
                    <xsl:for-each select="//town">      
                        <xsl:sort select="current()" data-type="number" order="descending"/>
                        <xsl:if test="position()&lt;= 8">
                       

                            <xsl:variable name="friendsGetTowns" select="sum(//town)"/>
                            <xsl:variable name="pos" select="position()"/>
                   

                   
                            <xsl:variable name="previous" select="sum(.|preceding-sibling::town) - current()"/>
                           
                            <xsl:element name="circle" >
                                <xsl:attribute name="cx">
                                    <xsl:value-of select="(current() div $friendsGetTowns * 100)div 2 + ($previous div $friendsGetTowns * 100)"/>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>
                                <xsl:attribute name="cy">50%</xsl:attribute>
                                <xsl:attribute name="r">
                                    <xsl:value-of select="(current() div $friendsGetTowns * 100) div 2"/>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>
                                <xsl:attribute name="stroke">black</xsl:attribute>    
                                <xsl:attribute name="stroke-width">0.2</xsl:attribute>
                                <xsl:attribute name="fill-opacity">
                                    <xsl:text>0.9</xsl:text>
                                </xsl:attribute>
                                <xsl:attribute name="fill">
                                    <xsl:if test="position() mod 8 = 0">
                                        <xsl:text>#cb72f4</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 = 1">
                                        <xsl:text>#08a789</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 = 2">
                                        <xsl:text>#afc21b</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 = 3">
                                        <xsl:text>#cb72f4</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 = 4">
                                        <xsl:text>#82bf56</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 = 5">
                                        <xsl:text>#3CB371</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 = 6">
                                        <xsl:text>#56b1bf</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 = 7">
                                        <xsl:text>#bf5676</xsl:text>
                                    </xsl:if>
                                </xsl:attribute>
                            </xsl:element>  
                               
                            <xsl:element name="text">
                                <xsl:attribute name="x">
                                    <xsl:value-of select="(current() div $friendsGetTowns * 100)div 4.5 + ($previous div $friendsGetTowns * 100)"/>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>
                                <xsl:attribute name="y">50%</xsl:attribute>
                                <xsl:attribute name="fill">
                                    <xsl:if test="position() mod 8 = 1">
                                        <xsl:text>#a0f2eb</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 =  2">
                                        <xsl:text>#a0f2eb</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 =  3">
                                        <xsl:text>#a0f2eb</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 =  4">
                                        <xsl:text>black</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 =  5">
                                        <xsl:text>black</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 =  6">
                                        <xsl:text>#black</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position() mod 8 =  7">
                                        <xsl:text>#black</xsl:text>
                                    </xsl:if>
                                </xsl:attribute>
                                   
                                <xsl:attribute name="font-family">Calibri</xsl:attribute>
                                <xsl:attribute name="font-anchor">left</xsl:attribute>
                                <xsl:if test="current() div $friendsGetTowns &gt;= 0.25">                            
                                    <xsl:attribute name="font-size">30px</xsl:attribute>
                                    <xsl:attribute name="font-weight">bold</xsl:attribute>
                                    <xsl:attribute name="y">53%</xsl:attribute>
                                    <xsl:attribute name="x">
                                        <xsl:value-of select="(current() div $friendsGetTowns * 100)div 4.5-1.5 + ($previous div $friendsGetTowns * 100)"/>
                                        <xsl:text>%</xsl:text>
                                    </xsl:attribute>
                                </xsl:if>
                                <xsl:if test="current() div $friendsGetTowns &lt;0.25 and current() div $friendsGetTowns &gt;=0.2">
                                    <xsl:attribute name="font-size">25px</xsl:attribute>
                                    <xsl:attribute name="font-weight">bold</xsl:attribute>
                                    <xsl:attribute name="y">55%</xsl:attribute>
                                </xsl:if>
                                <xsl:if test="current() div $friendsGetTowns &lt;0.2 and current() div $friendsGetTowns &gt;=0.15">
                                    <xsl:attribute name="font-size">16px</xsl:attribute>
                                    <xsl:attribute name="font-weight">bold</xsl:attribute>
                                    <xsl:attribute name="y">55%</xsl:attribute>                              
                                </xsl:if>
                                <xsl:if test="current() div $friendsGetTowns &lt;0.15 and current() div $friendsGetTowns &gt;=0.1">
                                    <xsl:attribute name="font-size">14px</xsl:attribute>
                                    <xsl:attribute name="font-weight">bold</xsl:attribute>
                                    <xsl:attribute name="y">55%</xsl:attribute>
                                </xsl:if>
                                <xsl:if test="current() div $friendsGetTowns &lt;0.1 and current() div $friendsGetTowns &gt;=0.05">
                                    <xsl:attribute name="font-size">11px</xsl:attribute>
                                    <xsl:attribute name="y">52%</xsl:attribute>
                                    <xsl:attribute name="x">
                                        <xsl:value-of select="(current() div $friendsGetTowns * 100)div 4.5-0.5 + ($previous div $friendsGetTowns * 100)"/>%
                                    </xsl:attribute>                            
                                </xsl:if>
                                <xsl:if test="current() div $friendsGetTowns &lt;0.05 and current() div $friendsGetTowns &gt;=0.02">
                                    <xsl:attribute name="font-size">9px</xsl:attribute>
                                    <xsl:attribute name="y">
                                        <xsl:text>50%</xsl:text>
                                    </xsl:attribute>
                                    <xsl:attribute name="x">
                                        <xsl:value-of select="(current() div $friendsGetTowns * 100)div 4.5- 3 + ($previous div $friendsGetTowns * 100)"/>
                                        <xsl:text>%</xsl:text>
                                    </xsl:attribute>
                                   
                                </xsl:if>
                                <xsl:if test="current() div $friendsGetTowns &lt;0.02">
                                    <xsl:attribute name="font-size">10px</xsl:attribute>
                                    <xsl:attribute name="y">50%</xsl:attribute>                              
                                </xsl:if>                              
                                <xsl:value-of select="@name"/>
                            </xsl:element>
                               
                            <xsl:element name="text">
                                <xsl:attribute name="x">
                                    <xsl:value-of select="(current() div $friendsGetTowns * 100)div 4 + ($previous div $friendsGetTowns * 100)"/>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>
                                <xsl:attribute name="y">45%</xsl:attribute>
                                <xsl:attribute name="fill">
                                    <xsl:if test="position() mod 8 = 1 or position() mod 8 = 2 or position() mod 8 = 3">
                                        <xsl:text>#e9f2a0</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="not(position() mod 8 = 1 or position() mod 8 = 2 or position() mod 8 = 3)">
                                        <xsl:text>black</xsl:text>
                                    </xsl:if>
                                </xsl:attribute>
                                <xsl:attribute name="font-family">Calibri</xsl:attribute>
                                <xsl:attribute name="font-anchor">middle</xsl:attribute>
                                   
                                <xsl:if test="current() div $friendsGetTowns &gt;= 0.25">                                    
                                    <xsl:attribute name="font-size">70px</xsl:attribute>
                                    <xsl:attribute name="font-weight">bold</xsl:attribute>
                                    <xsl:attribute name="y">43%</xsl:attribute>
                                    <xsl:attribute name="x">
                                        <xsl:value-of select="(current() div $friendsGetTowns * 100)div 4.5+4.5 + ($previous div $friendsGetTowns * 100)"/>
                                        <xsl:text>%</xsl:text>
                                    </xsl:attribute>
                                </xsl:if>
                                <xsl:if test="current() div $friendsGetTowns &lt;0.25 and current() div $friendsGetTowns &gt;=0.2">
                                    <xsl:attribute name="font-size">50px</xsl:attribute>
                                    <xsl:attribute name="font-weight">bold</xsl:attribute>
                                    <xsl:attribute name="y">45%</xsl:attribute>
                                </xsl:if>
                                <xsl:if test="current() div $friendsGetTowns &lt;0.15 and current() div $friendsGetTowns &gt;=0.1">
                                    <xsl:attribute name="font-size">10px</xsl:attribute>
                                    <xsl:attribute name="font-weight">bold</xsl:attribute>
                                </xsl:if>
                                <xsl:if test="current() div $friendsGetTowns &lt;0.1 and current() div $friendsGetTowns &gt;=0.05">
                                    <xsl:attribute name="y">46.8%</xsl:attribute>
                                    <xsl:attribute name="x">
                                        <xsl:value-of select="(current() div $friendsGetTowns * 100)div 4.5 +1.3+ ($previous div $friendsGetTowns * 100)"/>
                                        <xsl:text>%</xsl:text>
                                    </xsl:attribute>  
                                </xsl:if>
                                <xsl:if test="current() div $friendsGetTowns &lt;0.05 and current() div $friendsGetTowns &gt;=0.02">
                                    <xsl:attribute name="font-size">10px</xsl:attribute>
                                    <xsl:attribute name="y">46%</xsl:attribute>
                                    <xsl:attribute name="x">
                                        <xsl:value-of select="(current() div $friendsGetTowns * 100)div 4.5+4.5 + ($previous div $friendsGetTowns * 100)"/>
                                        <xsl:text>%</xsl:text>
                                    </xsl:attribute>
                                </xsl:if>
                                <xsl:if test="current() div $friendsGetTowns &lt;0.02">
                                    <xsl:attribute name="font-size">10px</xsl:attribute>
                                    <xsl:attribute name="y">45%</xsl:attribute>
                                </xsl:if>
                                   
                                   
                                <xsl:text>
                                    <xsl:value-of select="current()"/>
                                </xsl:text>
                            </xsl:element>
                                 
                           
                     
                        </xsl:if>
                    </xsl:for-each>
                </svg>
                <h3>2013</h3>

               
                <xsl:variable name="maxCount">
                    <xsl:choose>
                        <xsl:when test="count(//friend) &gt;= //friend[1]/mutual-friends/@count">
                            <xsl:value-of select="sum(//friend/@count)"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="sum(//friend[1]//mutual-friend/@mutual-count)"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>
               
                     
                           
                <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="95%" height="768">
                    
                    
                    
                    <xsl:variable name="count" select="//friends/@count"/>
                    <xsl:for-each select="//friend">  
                       
<xsl:variable name="maxR" select="(//friend[1]/mutual-friends/@count div $maxCount) * 70.710678"/>
                        <xsl:variable name="friend" select="."/>
                        <xsl:variable name="pos" select="position()"/>  
                        <!--<xsl:sort select="current()/mutual-frieds/@count" data-type="number" order="descending"/>-->
                        <xsl:variable name="mutualCount" select="./mutual-friends/@count"/>
                        <!--<xsl:if test="not(@id = current()/preceding-sibling::friend/mutual-friends/mutual-friend/@id)"><not(@id = preceding-sibling::friend//mutual-friend[count(preceding-sibling::mutual-friend) + 1 &gt;= (count(preceding-sibling::mutual-friend) + count(following-sibling::mutual-friend)) div 10]/@id)">-->
                       

                        <xsl:variable name="precedingCount">
                            <xsl:choose>
                                <xsl:when test="position() mod 2 = 0">
                                    <xsl:value-of select="sum(current()/preceding-sibling::friend[position() mod 2 = 0]/mutual-friends/@count)"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="sum(current()/preceding-sibling::friend[position() mod 2 = 1]/mutual-friends/@count)"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>
                        <xsl:variable name="location">
                            <xsl:choose>
                                <xsl:when test="position() mod 2 = 0">
                                    <xsl:value-of select="50 +  (70.710678 - $maxR - 2)*($precedingCount div ($maxCount div 2) + ($mutualCount div $maxCount)) div $root"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="50 -  (70.710678 - $maxR - 2)*($precedingCount div ($maxCount div 2)+ ($mutualCount div $maxCount)) div $root"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>
                        <xsl:variable name="r" select="$mutualCount div $maxCount * (70.710678 - $maxR - 2)"/>
                        <!--<xsl:for-each select="//other[@id = current()/@id]">
                           
                            <xsl:variable name="otherMutualCount" select="./mutual-friends[@id = current()/@id]/@count"/>
                            
                       

                            <xsl:variable name="otherPrecedingCount" select="sum(//friend[@id = current()/@id]/preceding-sibling::friend/mutual-friends/@count) div 2 + sum(//mutual-friend[@id = current()/@id]/preceding-sibling::mutual-friend//@mutual-Count) div 2 + sum(//mutual-friend[@id = current()/@id]/preceding-sibling::mutual-friend/@mutual-count) div 2 + sum(//mutual-friend[@id = current()/@id]/preceding-sibling::mutual-friend//@mutual-count) div 2"/>
                            <xsl:variable name="otherLocation">
                                <xsl:choose>
                                    <xsl:when test="position() mod 2 = 0">
                                        <xsl:value-of select="50 +  80*(($precedingCount div $maxCount) + ($mutualCount div $maxCount) div 2 )"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="50 -  80*(($precedingCount div $maxCount) + ($mutualCount div $maxCount) div 2 )"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:variable>
                           
                            <xsl:element name="line" >

                                <xsl:attribute name="x1">
                                    <xsl:value-of select="$location"/>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>


                                <xsl:attribute name="y1">
                                    <xsl:value-of select="$location"/>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>
                                
                                <xsl:attribute name="x2">
                                    <xsl:value-of select="$otherLocation"/>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>
                                
                                <xsl:attribute name="y2">
                                    <xsl:value-of select="$otherLocation"/>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>




                                <xsl:attribute name="stroke-width">1</xsl:attribute>
                                <xsl:attribute name="stroke">
                                    <xsl:text>black</xsl:text>
                                </xsl:attribute>


                                <xsl:attribute name="opacity">
                                    <xsl:text>0.9</xsl:text>
                                </xsl:attribute>

                            </xsl:element>  
                        </xsl:for-each>-->

                               
                        <xsl:for-each select="current()//mutual-friend">
                            <!--<xsl:if test="">position() + 1 &gt;= $mutualCount div 10">-->
                            <xsl:variable name="mutualFriendPosition" select="count(current()/preceding-sibling::mutual-friend) + 1"/>
                            <xsl:variable name="precedingMutualCount"> 
                                <xsl:choose>
                                    <xsl:when test="position() mod 2 = 0">
                                        <xsl:value-of select="sum(current()/preceding-sibling::mutual-friend[position() mod 2 = 0]/@mutual-count)"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="sum(current()/preceding-sibling::mutual-friend[position() mod 2 = 1]/@mutual-count)"/>
                                    </xsl:otherwise>
                                </xsl:choose> 
                            </xsl:variable>
                            <xsl:variable name="countFriends" select="@mutual-count"/>
                            <xsl:variable name="mutualLocation" select="@location"/>
                            
                            
                            <xsl:variable name="mutualId" select="current()/@id"/>
                             
                            <xsl:for-each select="//other[@id = current()/@id]">
                                <xsl:variable name="otherMutualFriendPosition" select="count(parent::mutual-friend/preceding-sibling::mutual-friend) + 1"/>
                                <xsl:variable name="otherR" select="(ancestor::friend/mutual-friends/@count div $maxCount) * (70.710678 - $maxR - 2)"/>
                                <xsl:variable name="otherPrecedingMutualCount">
                                    <xsl:choose>
                                        <xsl:when test="$otherMutualFriendPosition mod 2 = 0">
                                            <xsl:value-of select="sum(parent::mutual-friend/preceding-sibling::mutual-friend[position() mod 2 = 0]/@mutual-count)"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="sum(parent::mutual-friend/preceding-sibling::mutual-friend[position() mod 2 = 1]/@mutual-count)"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:variable>  
                                    
                                <xsl:variable name="otherCurrentMutualCount" select="parent::mutual-friend/@mutual-count"/>
 
                                
 
                                <xsl:variable name="otherMutualCount" select="ancestor::friend/mutual-friends/@count"/>
                                <xsl:variable name="otherPrecedingCount">
                                    <xsl:choose>
                                        <xsl:when test="(count(ancestor::friend/preceding-sibling::friend) + 1)  mod 2 = 0">
                                            <xsl:value-of select="sum(ancestor::friend/preceding-sibling::friend[position() mod 2 = 0]/mutual-friends/@count)"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="sum(ancestor::friend/preceding-sibling::friend[position() mod 2 = 1]/mutual-friends/@count)"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:variable>
                            
                                <xsl:variable name="maxLocation">
                                    <xsl:choose>
                                        <xsl:when test="name(parent::*) = 'mutual-friends'">
                                            <xsl:choose>
                                                <xsl:when test="ancestor::friend/mutual-friends/@count &gt;= $countFriends">
                                                    <xsl:value-of select="ancestor::friend/@location"/>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:value-of select="$mutualLocation"/>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:choose>
                                            <xsl:when test="parent::mutual-friend/@mutualCount &gt;= $countFriends">
                                                <xsl:value-of select="parent::mutual-friend/@location"/>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:value-of select="$mutualLocation"/>
                                            </xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:variable>
                                

                            
                                    <xsl:variable name="otherLocation">
                                        <xsl:choose>
                                            <xsl:when test="(count(ancestor::friend/preceding-sibling::friend) + 1) mod 2 = 0">
                                                <xsl:value-of select="50 +   (70.710678 - $maxR - 2)*(($otherPrecedingCount div ($maxCount div 2)) + ($otherMutualCount div $maxCount) ) div $root"/>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:value-of select="50 -   (70.710678 - $maxR - 2)*(($otherPrecedingCount div ($maxCount div 2)) + ($otherMutualCount div $maxCount) ) div $root"/>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:variable>
                    
                                    <xsl:element name="line" >

                                        <xsl:attribute name="x1">
                                            <xsl:choose>
                                                <xsl:when test="$mutualFriendPosition mod 2 = 0">
                                                    <xsl:value-of select="$location - ($r div $root + (70.710678 - $maxR - 2)*(($precedingMutualCount div ($maxCount div 2)) + ($countFriends div $maxCount)) div $root)"/>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:value-of select="$location + ($r div $root + (70.710678 - $maxR - 2)*(($precedingMutualCount div ($maxCount div 2)) + ($countFriends div $maxCount)) div $root)"/>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                            <xsl:text>%</xsl:text>
                                        </xsl:attribute>


                                        <xsl:attribute name="y1">
                                            <xsl:choose>
                                                <xsl:when test="$mutualFriendPosition mod 2 = 0">
                                                    <xsl:value-of select="$location + ($r div $root + (70.710678 - $maxR - 2)*(($precedingMutualCount div ($maxCount div 2)) + ($countFriends div $maxCount)) div $root)"/>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:value-of select="$location - ($r div $root + (70.710678 - $maxR - 2)*(($precedingMutualCount div ($maxCount div 2)) + ($countFriends div $maxCount)) div $root)"/>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                            <xsl:text>%</xsl:text>
                                        </xsl:attribute>
                                        
                                        <!--$location - 80*(($precedingMutualCount div $maxCount) + (@mutual-count div $maxCount) div 2 )-->
                                        

                                        
                                        <xsl:attribute name="x2">
                                            <xsl:choose>
                                                <xsl:when test="name(parent::*) = 'mutual-friends'">
                                                    <xsl:value-of select="$otherLocation"/>
  
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:choose>
                                                        <xsl:when test="(count(parent::mutual-friend/preceding-sibling::mutual-friend) + 1) mod 2 = 0">
                                                            <xsl:value-of select="$otherLocation - ($otherR div $root + (70.710678 - $maxR - 2)*(($otherPrecedingMutualCount div ($maxCount div 2)) + ($otherCurrentMutualCount div $maxCount)) div $root)"/>
                                                        </xsl:when>
                                                        <xsl:otherwise>
                                                            <xsl:value-of select="$otherLocation + ($otherR div $root + (70.710678 - $maxR - 2)*(($otherPrecedingMutualCount div ($maxCount div 2)) + ($otherCurrentMutualCount div $maxCount)) div $root)"/>
                                                        </xsl:otherwise>
                                                    </xsl:choose>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                            <xsl:text>%</xsl:text>
                                        </xsl:attribute>
                                
                                        <xsl:attribute name="y2">
                                            <xsl:choose>
                                                <xsl:when test="name(parent::*) = 'mutual-friends'">
                                                    <xsl:value-of select="$otherLocation"/>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:choose>
                                                        <xsl:when test="(count(parent::mutual-friend/preceding-sibling::mutual-friend) + 1) mod 2 = 0">
                                                            <xsl:value-of select="$otherLocation + ($otherR div $root + (70.710678 - $maxR - 2)*(($otherPrecedingMutualCount div ($maxCount div 2)) + ($otherCurrentMutualCount div $maxCount)) div $root)"/>
                                                        </xsl:when>
                                                        <xsl:otherwise>
                                                            <xsl:value-of select="$otherLocation - ($otherR div $root + (70.710678 - $maxR - 2)*(($otherPrecedingMutualCount div ($maxCount div 2)) + ($otherCurrentMutualCount div $maxCount)) div $root)"/>
                                                        </xsl:otherwise>
                                                    </xsl:choose>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                            <xsl:text>%</xsl:text>
                                        </xsl:attribute>

                                        <!--"$location - ($r + (70.710678 - $maxR - 2)*($precedingMutualCount div ($maxCount div 2) + (@mutual-count div $maxCount))) div $root"-->


                                        <xsl:attribute name="stroke-width">
                                                <xsl:text>0.1</xsl:text>
                                        </xsl:attribute>
                                        
                                        <xsl:attribute name="stroke">
                                        <xsl:choose>
                                        <xsl:when test="$maxLocation = //town[1]/@name">
                                            <xsl:text>#08a789</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="$maxLocation = //town[2]/@name">
                                            <xsl:text>#afc21b</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="$maxLocation = //town[3]/@name">
                                            <xsl:text>#cb72f4</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="$maxLocation = //town[4]/@name">
                                            <xsl:text>#82bf56</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="$maxLocation = //town[5]/@name">
                                            <xsl:text>#3CB371</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="$maxLocation = //town[6]/@name">
                                            <xsl:text>#56b1bf</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="$maxLocation = //town[7]/@name">
                                            <xsl:text>#bf5676</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="$maxLocation = //town[8]/@name">
                                            <xsl:text>#cb72f4</xsl:text>
                                        </xsl:when>
                                   
                                        <xsl:otherwise>
                                            <xsl:text>#C0C0C0</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                        </xsl:attribute>
                                    </xsl:element>
                               
                            </xsl:for-each>
                               
                            
                           
                            <!--</xsl:if>-->
                        </xsl:for-each>      
                       
                     
                        <!--</xsl:if>-->
                    </xsl:for-each>
                    
                    
                    <xsl:for-each select="//friend">  
                       
                        <!--<xsl:if test="not(@id = preceding-sibling::friend/mutual-friends/mutual-friend/@id)">-->
                        <xsl:variable name="maxR" select="(//friend[1]/mutual-friends/@count div $maxCount) * 70.710678"/>
                        <xsl:variable name="friend" select="."/>
                        <xsl:variable name="pos" select="position()"/>  
                        <!--<xsl:sort select="current()/mutual-frieds/@count" data-type="number" order="descending"/>-->
                        <xsl:variable name="mutualCount" select="./mutual-friends/@count"/>
                        <!--<xsl:if test="not(@id = current()/preceding-sibling::friend/mutual-friends/mutual-friend/@id)"><not(@id = preceding-sibling::friend//mutual-friend[count(preceding-sibling::mutual-friend) + 1 &gt;= (count(preceding-sibling::mutual-friend) + count(following-sibling::mutual-friend)) div 10]/@id)">-->
                       

                        <xsl:variable name="precedingCount">
                            <xsl:choose>
                                <xsl:when test="position() mod 2 = 0">
                                    <xsl:value-of select="sum(current()/preceding-sibling::friend[position() mod 2 = 0]/mutual-friends/@count)"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="sum(current()/preceding-sibling::friend[position() mod 2 = 1]/mutual-friends/@count)"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>
                        <xsl:variable name="location">
                            <xsl:choose>
                                <xsl:when test="position() mod 2 = 0">
                                    <xsl:value-of select="50 +  (70.710678 - $maxR - 2)*($precedingCount div ($maxCount div 2) + ($mutualCount div $maxCount)) div $root"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="50 -  (70.710678 - $maxR - 2)*($precedingCount div ($maxCount div 2)+ ($mutualCount div $maxCount)) div $root"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>
                        <xsl:variable name="r" select="$mutualCount div $maxCount * (70.710678 - $maxR - 2)"/>
                       
                        <xsl:element name="circle" >

                            <xsl:attribute name="cx">
                                <xsl:value-of select="$location"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>

                               
                            <xsl:attribute name="cy">
                                <xsl:value-of select="$location"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                               
                            <xsl:attribute name="r">
                                <xsl:value-of select="$r"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="stroke-width">0.3</xsl:attribute>
                            <xsl:attribute name="stroke">
                                <xsl:text>black</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="fill">
                                <xsl:choose>
                                    <xsl:when test="@location = //town[1]/@name">
                                        <xsl:text>#08a789</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="@location = //town[2]/@name">
                                        <xsl:text>#afc21b</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="@location = //town[3]/@name">
                                        <xsl:text>#cb72f4</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="@location = //town[4]/@name">
                                        <xsl:text>#82bf56</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="@location = //town[5]/@name">
                                        <xsl:text>#3CB371</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="@location = //town[6]/@name">
                                        <xsl:text>#56b1bf</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="@location = //town[7]/@name">
                                        <xsl:text>#bf5676</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="@location = //town[8]/@name">
                                        <xsl:text>#cb72f4</xsl:text>
                                    </xsl:when>
                                   
                                    <xsl:otherwise>
                                        <xsl:text>#C0C0C0</xsl:text>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:attribute>
                           
                            <xsl:attribute name="opacity">
                                <xsl:text>0.9</xsl:text>
                            </xsl:attribute>
                           
                        </xsl:element>  

                               
                        <xsl:for-each select="current()//mutual-friend">
                            <!--<xsl:if test="">position() + 1 &gt;= $mutualCount div 10">-->
                            <xsl:variable name="mutualFriendPosition" select="count(current()/preceding-sibling::mutual-friend) + 1"/>
                            <xsl:variable name="precedingMutualCount"> 
                                <xsl:choose>
                                    <xsl:when test="position() mod 2 = 0">
                                        <xsl:value-of select="sum(current()/preceding-sibling::mutual-friend[position() mod 2 = 0]/@mutual-count)"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="sum(current()/preceding-sibling::mutual-friend[position() mod 2 = 1]/@mutual-count)"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:variable> 
                               
                            <xsl:element name="circle" >
                               
                                <xsl:attribute name="cx">
                                    <xsl:choose>
                                        <xsl:when test="position() mod 2 = 0">
                                            <xsl:value-of select="$location - ($r + (70.710678 - $maxR - 2)*($precedingMutualCount div ($maxCount div 2) + (@mutual-count div $maxCount))) div $root"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="$location + ($r + (70.710678 - $maxR - 2)*($precedingMutualCount div ($maxCount div 2) + (@mutual-count div $maxCount))) div $root"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>  
 
                               
                                <xsl:attribute name="cy">
                                    <xsl:choose>
                                        <xsl:when test="position() mod 2 = 0">
                                            <xsl:value-of select="$location + ($r + (70.710678 - $maxR - 2)*($precedingMutualCount div ($maxCount div 2) + (@mutual-count div $maxCount))) div $root"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="$location - ($r + (70.710678 - $maxR - 2)*($precedingMutualCount div ($maxCount div 2) + (@mutual-count div $maxCount))) div $root"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>  
 
                                   
                                <xsl:attribute name="r">
                                    <xsl:value-of select="@mutual-count div $maxCount * (70.710678 - $maxR - 2) "/>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>
                                <xsl:attribute name="stroke-width">0.2</xsl:attribute>
                                <xsl:attribute name="stroke">
                                    <xsl:text>black</xsl:text>
                                </xsl:attribute>
                                <xsl:attribute name="fill">
                                    <xsl:choose>
                                        <xsl:when test="@location = //town[1]/@name">
                                            <xsl:text>#08a789</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="@location = //town[2]/@name">
                                            <xsl:text>#afc21b</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="@location = //town[3]/@name">
                                            <xsl:text>#cb72f4</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="@location = //town[4]/@name">
                                            <xsl:text>#82bf56</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="@location = //town[5]/@name">
                                            <xsl:text>#3CB371</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="@location = //town[6]/@name">
                                            <xsl:text>#56b1bf</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="@location = //town[7]/@name">
                                            <xsl:text>#bf5676</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="@location = //town[8]/@name">
                                            <xsl:text>#cb72f4</xsl:text>
                                        </xsl:when>
                                   
                                        <xsl:otherwise>
                                            <xsl:text>#C0C0C0</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                               
                                </xsl:attribute>
                           
                                <xsl:attribute name="opacity">
                                    <xsl:text>0.9</xsl:text>
                                </xsl:attribute>
                           
                            </xsl:element>  
                           
                            <!--</xsl:if>-->
                        </xsl:for-each> 
                    </xsl:for-each> 
                    <xsl:for-each select="//friend">  
                       
                        <!--<xsl:if test="not(@id = preceding-sibling::friend/mutual-friends/mutual-friend/@id)">-->
                        <xsl:variable name="maxR" select="(//friend[1]/mutual-friends/@count div $maxCount) * 70.710678"/>
                        <xsl:variable name="friend" select="."/>
                        <xsl:variable name="pos" select="position()"/>  
                        <!--<xsl:sort select="current()/mutual-frieds/@count" data-type="number" order="descending"/>-->
                        <xsl:variable name="mutualCount" select="./mutual-friends/@count"/>
                        <!--<xsl:if test="not(@id = current()/preceding-sibling::friend/mutual-friends/mutual-friend/@id)"><not(@id = preceding-sibling::friend//mutual-friend[count(preceding-sibling::mutual-friend) + 1 &gt;= (count(preceding-sibling::mutual-friend) + count(following-sibling::mutual-friend)) div 10]/@id)">-->
                       

                        <xsl:variable name="precedingCount">
                            <xsl:choose>
                                <xsl:when test="position() mod 2 = 0">
                                    <xsl:value-of select="sum(current()/preceding-sibling::friend[position() mod 2 = 0]/mutual-friends/@count)"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="sum(current()/preceding-sibling::friend[position() mod 2 = 1]/mutual-friends/@count)"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>
                        <xsl:variable name="location">
                            <xsl:choose>
                                <xsl:when test="position() mod 2 = 0">
                                    <xsl:value-of select="50 +  (70.710678 - $maxR - 2)*($precedingCount div ($maxCount div 2) + ($mutualCount div $maxCount)) div $root"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="50 -  (70.710678 - $maxR - 2)*($precedingCount div ($maxCount div 2)+ ($mutualCount div $maxCount)) div $root"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>
                        <xsl:variable name="r" select="$mutualCount div $maxCount * (70.710678 - $maxR - 2)"/>
                      
                       
                        <xsl:if test="current()/mutual-friends/@count &gt;= $count div 10 or count(current()/mutual-friends/mutual-friend) &gt;= $count div 50">
                            <xsl:element name="text">
                                <xsl:attribute name="x">
                                    <xsl:value-of select="$location - 0.8*$r"/>
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>

                               
                                <xsl:attribute name="y">
                               
                                    <xsl:value-of select="$location"/>
                               
                                    <xsl:text>%</xsl:text>
                                </xsl:attribute>
                                
                                
                                <xsl:attribute name="fill">black</xsl:attribute>
                                <xsl:attribute name="font-family">Arial, Tahoma</xsl:attribute>
                                <xsl:attribute name="font-anchor">middle</xsl:attribute>
                                <xsl:attribute name="font-size">
                                    <xsl:choose>
                                        <xsl:when test="mutual-friends/@count &gt;= $count div 5">
                                            <xsl:text>10px</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="mutual-friends/@count &gt;= $count div 10 and mutual-friends/@count &lt; $count div 5">
                                            <xsl:text>9px</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="mutual-friends/@count &gt;= $count div 20 and mutual-friends/@count &lt; $count div 10">
                                            <xsl:text>8px</xsl:text>
                                        </xsl:when>
                                        <xsl:when test="mutual-friends/@count &gt;= $count div 40 and mutual-friends/@count &lt; $count div 20">
                                            <xsl:text>7px</xsl:text>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>7px</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:attribute>
                                <xsl:attribute name="font-weight">
                                    <xsl:choose>
                                    <xsl:when test="mutual-friends/@count &gt;= $count div 5">
                                        <xsl:text>bold</xsl:text>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:text>normal</xsl:text>
                                    </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:attribute>
                                <xsl:value-of select="@short-name"/>
                            </xsl:element>
                        </xsl:if>
                        <xsl:for-each select="current()//mutual-friend">
                            <!--<xsl:if test="">position() + 1 &gt;= $mutualCount div 10">-->
                            <xsl:variable name="mutualFriendPosition" select="count(current()/preceding-sibling::mutual-friend) + 1"/>
                            <xsl:variable name="precedingMutualCount"> 
                                <xsl:choose>
                                    <xsl:when test="position() mod 2 = 0">
                                        <xsl:value-of select="sum(current()/preceding-sibling::mutual-friend[position() mod 2 = 0]/@mutual-count)"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="sum(current()/preceding-sibling::mutual-friend[position() mod 2 = 1]/@mutual-count)"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:variable> 
                            
                            <xsl:if test="@mutual-count &gt;= $count div 10">
                                <xsl:element name="text">
                           
                                    <xsl:attribute name="x">
                                        <xsl:choose>
                                            <xsl:when test="position() mod 2 = 0">
                                           
                                                <xsl:value-of select="$location - ($r + (70.710678 - $maxR - 2)*($precedingMutualCount div ($maxCount div 2) + 1.8*(@mutual-count div $maxCount))) div $root"/>
                 
                                            </xsl:when>
                                            <xsl:otherwise>
                                           
                                                <xsl:value-of select="$location + ($r + (70.710678 - $maxR - 2)*($precedingMutualCount div ($maxCount div 2) + 0.2 * (@mutual-count div $maxCount))) div $root"/>
               
                                            </xsl:otherwise>
                                        </xsl:choose>
                                        <xsl:text>%</xsl:text>
                                    </xsl:attribute>  
 
                               
                                    <xsl:attribute name="y">
                                        <xsl:choose>
                                            <xsl:when test="position() mod 2 = 0">
                                                <xsl:value-of select="$location + ($r + (70.710678 - $maxR - 2)*($precedingMutualCount div ($maxCount div 2) + (@mutual-count div $maxCount))) div $root"/>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:value-of select="$location - ($r + (70.710678 - $maxR - 2)*($precedingMutualCount div ($maxCount div 2) + (@mutual-count div $maxCount))) div $root"/>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                        <xsl:text>%</xsl:text>
                                    </xsl:attribute>  
                                   
                                    <xsl:attribute name="fill">black</xsl:attribute>
                                    <xsl:attribute name="font-family">Arial, Tahoma</xsl:attribute>
                                    <xsl:attribute name="font-anchor">middle</xsl:attribute>
                                    <xsl:attribute name="font-size">
                                        <xsl:choose>
                                            <xsl:when test="@mutual-count &gt;= $count div 5">
                                                <xsl:text>10px</xsl:text>
                                            </xsl:when>
                                            <xsl:when test="@mutual-count &gt;= $count div 10 and @mutual-count &lt; $count div 5">
                                                <xsl:text>9px</xsl:text>
                                            </xsl:when>
                                            <xsl:when test="@mutual-count &gt;= $count div 20 and @mutual-count &lt; $count div 10">
                                                <xsl:text>8px</xsl:text>
                                            </xsl:when>
                                            <xsl:when test="@mutual-count &gt;= $count div 40 and @mutual-count &lt; $count div 20">
                                                <xsl:text>7px</xsl:text>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:text>6px</xsl:text>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:attribute>
                                    <xsl:value-of select="@short-name"/>
                                </xsl:element>
                            </xsl:if>
                        </xsl:for-each>
                    </xsl:for-each>
                </svg>
                <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="95%" height="600">
                    <xsl:for-each select="//conversation[position() &lt;= 10]">
                        <xsl:variable name="totalMessages" select="//conversations/@total"/>
                        <xsl:element name="rect">
                            <xsl:attribute name="x">
                                <xsl:value-of select="position() * 9"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="y">
                                <xsl:value-of select="100 - current() div $totalMessages * 100"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="width">
                                <xsl:text>7%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="height">
                                <xsl:value-of select="current() div $totalMessages * 100"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="fill">
                                <xsl:choose>
                                    <xsl:when test="//friend[@id = current()/@id]/@location = //town[1]/@name or //mutual-friend[@id = current()/@id]/@location = //town[1]/@name">
                                        <xsl:text>#08a789</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="//friend[@id = current()/@id]/@location = //town[2]/@name or //mutual-friend[@id = current()/@id]/@location = //town[2]/@name">
                                        <xsl:text>#afc21b</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="//friend[@id = current()/@id]/@location = //town[3]/@name or //mutual-friend[@id = current()/@id]/@location = //town[3]/@name">
                                        <xsl:text>#cb72f4</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="//friend[@id = current()/@id]/@location = //town[4]/@name or //mutual-friend[@id = current()/@id]/@location = //town[4]/@name">
                                        <xsl:text>#82bf56</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="//friend[@id = current()/@id]/@location = //town[5]/@name or //mutual-friend[@id = current()/@id]/@location = //town[5]/@name">
                                        <xsl:text>#3CB371</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="//friend[@id = current()/@id]/@location = //town[6]/@name or //mutual-friend[@id = current()/@id]/@location = //town[6]/@name">
                                        <xsl:text>#56b1bf</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="//friend[@id = current()/@id]/@location = //town[7]/@name or //mutual-friend[@id = current()/@id]/@location = //town[7]/@name">
                                        <xsl:text>#bf5676</xsl:text>
                                    </xsl:when>
                                    <xsl:when test="//friend[@id = current()/@id]/@location = //town[8]/@name or //mutual-friend[@id = current()/@id]/@location = //town[8]/@name">
                                        <xsl:text>#cb72f4</xsl:text>
                                    </xsl:when>
                                   
                                    <xsl:otherwise>
                                        <xsl:text>#C0C0C0</xsl:text>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:attribute>
                        </xsl:element>
                        <xsl:element name="image">
                            <xsl:attribute name="xlink:href">
                                <xsl:value-of select="//friend[@id = current()/@id]/@picture | //mutual-friend[@id = current()/@id]/@picture"/>
                            </xsl:attribute>
                            <xsl:attribute name="x">
                                <xsl:value-of select="position() * 9"/>
                                <xsl:text>%</xsl:text>

                            </xsl:attribute>
                            <xsl:attribute name="y">
                                <xsl:value-of select="100 - current() div $totalMessages * 100 - 10"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="width">
                                <xsl:text>40</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="height">
                                <xsl:text>40</xsl:text>
                            </xsl:attribute>
                        </xsl:element>
                        <xsl:element name="text">
                            <xsl:attribute name="x">
                                <xsl:value-of select="position() * 9 + 4"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="y">
                                <xsl:value-of select="100 - current() div $totalMessages * 100 - 6"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="font-family">
                                <xsl:text>Arial, Tahoma</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="font-size">
                                <xsl:text>12px</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="font-weight">
                                <xsl:text>bold</xsl:text>
                            </xsl:attribute>
                            <xsl:value-of select="round(current() div $totalMessages * 10000) div 100"/>
                            <xsl:text>%</xsl:text>  
                        </xsl:element>
                   
                        <xsl:element name="text">
                            <xsl:attribute name="x">
                                <xsl:value-of select="position() * 9"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="y">
                                <xsl:value-of select="100 - current() div $totalMessages * 100 - 11"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="font-family">
                                <xsl:text>Arial, Tahoma</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="font-size">
                                <xsl:text>11px</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="stroke-width">
                                <xsl:text>0.1px</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="stroke">
                                <xsl:text>black</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="fill">
                                <xsl:text>#808080</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="font-weight">
                                <xsl:text>bold</xsl:text>
                            </xsl:attribute>
                       

                            <xsl:value-of select="@name"/> 
                        </xsl:element>
                   
                        <xsl:element name="text">
                            <xsl:attribute name="x">
                                <xsl:value-of select="position() * 9 + 4"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="y">
                                <xsl:value-of select="100 - current() div $totalMessages * 100 - 4"/>
                                <xsl:text>%</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="font-family">
                                <xsl:text>Arial, Tahoma</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="font-size">
                                <xsl:text>8px</xsl:text>
                            </xsl:attribute>
                            <xsl:attribute name="fill">
                                <xsl:text>#808080</xsl:text>
                            </xsl:attribute>
                            <xsl:value-of select="current()"/>
                            <xsl:text> messages</xsl:text>
                        </xsl:element>
                    </xsl:for-each>
                </svg>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

